<template>
  <div class="app-container calendar-list-container">

    <div class="filter-container">
      <div class="filter-item">
        <el-select style="margin-left:10px;" v-model="listQuery.param.buyer" placeholder="请选择" clearable>
          <el-option v-for="item in userRole" :key="item.id" :label="item.userName" :value="item.id">
            <span style="float: left">{{ item.userName }}</span>
            <span style="float: right; color: #8492a6; font-size: 13px">{{ item.roles }}</span>
          </el-option>
        </el-select>
        <el-date-picker :clearable="false" style="margin-left:10px;" v-model="dateFilter" type="daterange" range-separator="-" format="yyyy-MM-dd" :default-time="['00:00:00', '23:59:59']" value-format="yyyy-MM-dd" @change="dateChange" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
        <el-button type="primary" icon="el-icon-search" style="margin-left:10px;" @click="handleFilter">查询</el-button>
      </div>
    </div>

    <el-table :data="listDatas" style="width: 100%">
      <el-table-column prop="amount" label="资金数目" width="200"></el-table-column>
      <el-table-column prop="plan" label="资金计划" show-overflow-tooltip></el-table-column>
      <el-table-column prop="buyerUser" label="申请人" width="200"></el-table-column>
      <el-table-column prop="createTime" label="申请时间" width="200"></el-table-column>
    </el-table>

    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 30, 50]" :total="totalCount" small>
    </el-pagination>

  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import { queryPurchaseOrder } from '@/api/purchaseOrder.js'
import { getAllUser } from '@/api/user'

export default {
  name: 'purchaseOrder',
  created() {
    let now = new Date();
    this.dateFilter[0] = new Date(now.getFullYear(), now.getMonth(), 1);
    this.dateFilter[1] = new Date(now.getFullYear(), now.getMonth() + 1, 0);
    this.listQuery.param.startTime = this.dateFilter[0];
    this.listQuery.param.endTime = this.dateFilter[1];
    this.getAllUserRoleInfo();
    this.handleFilter();
  },
  computed: {
    ...mapGetters(["elements"])
  },
  mounted() {
  },
  data() {
    return {
      dateFilter: [],
      listDatas: [],
      totalCount: undefined,
      listQuery: {
        page: 1,
        size: 10,
        param: {
          startTime: undefined,
          endTime: undefined,
          buyer: undefined
        }
      },
      userQuery: {
        page: 1,
        size: 2147483640,
        param: {}
      },
      userRole: []
    }
  },
  methods: {
    getlistDatas() {
      queryPurchaseOrder(this.listQuery).then(resp => {
        this.listDatas = resp.datas.datas;
        this.totalCount = resp.datas.total;
      });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getlistDatas();
    },
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.getlistDatas();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getlistDatas();
    },
    dateChange(val) {
      if (val) {
        this.listQuery.param.startTime = val[0];
        this.listQuery.param.endTime = val[1];
      }
      else {
        this.listQuery.param.startTime = undefined;
        this.listQuery.param.endTime = undefined;
      }
    },
    getAllUserRoleInfo() {
      getAllUser(this.userQuery).then(resp => {
        this.userRole = resp.datas.datas;
      });
    },
  }
}
</script>